package com.cryptoneedle.center.entity.doris;

import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.center.common.key.DatabaseKey;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
 * <p>description: Doris-元数据-Database </p>
 *
 * 整合参考：
 * 1.SHOW SHOW DATABASES FROM internal; 信息完整
 * 2.SELECT * FROM information_schema.schemata; 信息缺失，不同步
 *
 * @author CryptoNeedle
 * @date 2025-09-25
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "public", name = "doris_database")
@IdClass(DatabaseKey.class)
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Comment("Doris-Database")
public class DorisDatabase extends BaseEntity {

    @Id
    @Column(length = 512)
    @Comment("所属 Catalog")
    private String catalogName;

    @Id
    @Column(length = 64)
    @Comment("所属 Database")
    private String databaseName;

    public DatabaseKey getKey() {
        return new DatabaseKey(this.catalogName, this.databaseName);
    }

    public String getKeyString() {
        return getKey().toString();
    }
}